from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.core.mail import send_mail
from django.shortcuts import redirect
from django import forms
from django.utils import translation

class SendMail(forms.Form):
    subject = forms.CharField(widget=forms.TextInput(attrs={'size':'48'}), label=_('Theme'))
    from_mail = forms.EmailField(max_length=32, label=_('Your e-mail'))
    message = forms.CharField(widget=forms.Textarea(attrs={'cols':'18', 'rows':'5'}), label=_('Message'))
    
def contact(request):
    if request.method == 'POST':
        form = SendMail(request.POST)
        if form.is_valid():
            subject = form.cleaned_data['subject'] + " From: " + form.cleaned_data['from_mail']
            message = form.cleaned_data['message']
            sender = "info@vladimirkonovalov.com"
            recipients = ['a_mer@i.ua', 'dixon.che@gmail.com', 'info@vladimirkonovalov.com']
            
            send_mail(subject, message, sender, recipients)

            if translation.get_language()=='ru':
                return redirect("contact-ru")
            else:
                return redirect("contact-en")
    else:
        form = SendMail()
    return render_to_response('contacts.html', RequestContext(request, dict(form=form)))
